package com.ruyue.csinstall.command;

import com.ruyue.csinstall.utils.Utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.List;

/**
 * @author xiawl
 * @create 2017/7/23 14:55.
 */
public class MacroCommand implements Command{
    private static final Log log = LogFactory.getLog(MacroCommand.class);
    List<Command> commandList;

    public MacroCommand(List<Command> commandList) {
        this.commandList = commandList;
    }

    @Override
    public boolean execute(){
        int size = commandList.size();
        for(int k = 0; k < size; k++){
            Command command = commandList.get(k);
            if(!command.execute()){
                return false;
            }
            Utils.sleep(300);
            log.info(String.format("当前进度为[%s]", Utils.getPercent(k+1, size)));
        }
        return true;
    }
}